package com.zl.dynamicProxy;/**
 * @author suke
 * @create 2021-08-02 15:03
 */

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * TODO
 * @ClassName: Test
 * @author: suke
 * @since: 2021/8/2 15:03
 */
public class Test {
    public static void main(String[] args) {
      Coffee coffee = new Coffee();
        DrinkInvocationHandler drinkInvocationHandler = new DrinkInvocationHandler(coffee);
       //System.out.println(drinkInvocationHandler.getProxy() == tea);  //false

        //System.out.println(drinkInvocationHandler.getProxy());  //得到tea的代理类对象

        //Tea proxy =  (Tea)drinkInvocationHandler.getProxy();
        //proxy.fun(); //调用代理类的方法
        Drink proxy = (Drink)Proxy.newProxyInstance(coffee.getClass().getClassLoader(),coffee.getClass().getInterfaces(),drinkInvocationHandler);
       // System.out.println(obj.toString());
       //通过代理类对象调用方法
        //proxy.drink();


        proxy.fun();



    }
}
